package com.example.demo.service.impl;

import com.example.demo.domain.Score;
import com.example.demo.domain.Student;
import com.example.demo.mapper.ScoreMapper;
import com.example.demo.mapper.StudentMapper;
import com.example.demo.service.ScoreService;
import com.example.demo.util.ScoreUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ScoreServiceImpl implements ScoreService {
    //首先定义出来所有的科目
    private String[] courses = {"java", "高数", "c语言", "英语"};

    @Resource
    private StudentMapper studentMapper;

    @Resource
    private ScoreMapper scoreMapper;

    @Override
    public void generateScore() {
        //首先查询所有的学生
        List<Student> students = studentMapper.selectAll();
        Score score = null;
        if (students != null && students.size() > 0) {
            for (Student student : students) {
                for (String course : courses) {
                    score = new Score();
                    score.setCourse(course);
                    score.setStId(student.getId());
                    score.setScore(ScoreUtil.scoreUtil.getScore());
                    scoreMapper.insert(score);
                }
            }
        }
    }
}
